﻿'/* Copyright (c) 2009, Graeme Grant (graeme@live.com.au)
' * All rights reserved.
' *
' * Redistribution and use in source and binary forms, with or without
' * modification, are permitted provided that the following conditions are met:
' *
' *   * Redistributions of source code must retain the above copyright
' *     notice, this list of conditions and the following disclaimer.
' * 
' *   * Redistributions in binary form must reproduce the above copyright
' *     notice, this list of conditions and the following disclaimer in the
' *     documentation and/or other materials provided with the distribution.
' * 
' *   * The name Graeme Grant may not be used to endorse or promote products
' *     derived from this software without specific prior written permission.
' *
' * THIS SOFTWARE IS PROVIDED BY GRAEME GRANT ``AS IS'' AND ANY
' * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
' * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
' * DISCLAIMED. IN NO EVENT SHALL Dr. WPF BE LIABLE FOR ANY
' * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
' * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
' * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
' * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
' * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
' * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
' */

Imports System.Xml.Serialization
Imports System.IO

<Serializable()> _
Public Class Shop : Inherits User

#Region "Constructor"

    Public Sub New()
        MyBase.New()
    End Sub

    Friend Sub New(ByVal Details As Hashtable)
        MyBase.New(Details)
        ExtractDetails(Details)
    End Sub

    Friend Sub New(ByVal _json As String)
        MyBase.New(_json)
        ExtractDetails(CType(JSON.JsonDecode(_json), Hashtable)("results")(0))
    End Sub

#End Region

#Region "Public Properties"


    <XmlElement("banner_image_url")> _
    Private _banner_image_url As String
    Public Property BannerImageURL() As String
        Get
            Return _banner_image_url
        End Get
        Set(ByVal value As String)
            _banner_image_url = value
        End Set
    End Property

    <XmlElement("last_updated_epoch")> _
    Private _last_updated As Date
    Public Property LastUpdated() As Date
        Get
            Return _last_updated
        End Get
        Set(ByVal value As Date)
            _last_updated = value
        End Set
    End Property

    <XmlElement("creation_epoch")> _
    Private _creation As Date
    Public Property creation() As Date
        Get
            Return _creation
        End Get
        Set(ByVal value As Date)
            _creation = value
        End Set
    End Property

    <XmlElement("listing_count")> _
    Private _listing_count As Integer
    Public Property listingcount() As Integer
        Get
            Return _listing_count
        End Get
        Set(ByVal value As Integer)
            _listing_count = value
        End Set
    End Property

    <XmlElement("shop_name")> _
    Private _shop_name As String
    Public Property ShopName() As String
        Get
            Return _shop_name
        End Get
        Set(ByVal value As String)
            _shop_name = value
        End Set
    End Property

    <XmlElement("title")> _
    Private _title As String
    Public Property Title() As String
        Get
            Return _title
        End Get
        Set(ByVal value As String)
            _title = value
        End Set
    End Property

    <XmlElement("sale_message")> _
    Private _sale_message As String
    Public Property SaleMessage() As String
        Get
            Return _sale_message
        End Get
        Set(ByVal value As String)
            _sale_message = value
        End Set
    End Property

    <XmlElement("announcement")> _
    Private _announcement As String
    Public Property Announcement() As String
        Get
            Return _announcement
        End Get
        Set(ByVal value As String)
            _announcement = value
        End Set
    End Property

    <XmlElement("is_vacation")> _
    Private _is_vacation As Boolean
    Public Property IsVacation() As Boolean
        Get
            Return _is_vacation
        End Get
        Set(ByVal value As Boolean)
            _is_vacation = value
        End Set
    End Property

    <XmlElement("vacation_message")> _
    Private _vacation_message As String
    Public Property VacationMessage() As String
        Get
            Return _vacation_message
        End Get
        Set(ByVal value As String)
            _vacation_message = value
        End Set
    End Property

    <XmlElement("currency_code")> _
    Private _currency_code As String
    Public Property CurrencyCode() As String
        Get
            Return _currency_code
        End Get
        Set(ByVal value As String)
            _currency_code = value
        End Set
    End Property

    <XmlElement("policy_welcome")> _
    Private _policy_welcome As String
    Public Property PolicyWelcome() As String
        Get
            Return _policy_welcome
        End Get
        Set(ByVal value As String)
            _policy_welcome = value
        End Set
    End Property

    <XmlElement("policy_payment")> _
    Private _policy_payment As String
    Public Property PolicyPayment() As String
        Get
            Return _policy_payment
        End Get
        Set(ByVal value As String)
            _policy_payment = value
        End Set
    End Property

    <XmlElement("policy_shipping")> _
    Private _policy_shipping As String
    Public Property PolicyShipping() As String
        Get
            Return _policy_shipping
        End Get
        Set(ByVal value As String)
            _policy_shipping = value
        End Set
    End Property

    <XmlElement("policy_refunds")> _
    Private _policy_refunds As String
    Public Property PolicyRefunds() As String
        Get
            Return _policy_refunds
        End Get
        Set(ByVal value As String)
            _policy_refunds = value
        End Set
    End Property

    <XmlElement("policy_additional")> _
    Private _policy_additional As String
    Public Property PolicyAdditional() As String
        Get
            Return _policy_additional
        End Get
        Set(ByVal value As String)
            _policy_additional = value
        End Set
    End Property

    <XmlElement("Sections")> _
    Private _sections As ShopSections(Of ShopSection)
    Public Property Sections() As ShopSections(Of ShopSection)
        Get
            Return _sections
        End Get
        Set(ByVal value As ShopSections(Of ShopSection))
            _sections = value
        End Set
    End Property

#End Region

#Region "Support Methods & Functions"

    Private Sub ExtractDetails(ByVal Details As Hashtable)

        _banner_image_url = Details("banner_image_url")
        _last_updated = JSON.DecodeDateTime(Details("last_updated_epoch"))
        _creation = JSON.DecodeDateTime(Details("creation_epoch"))
        _listing_count = CInt(Details("listing_count"))
        _shop_name = Details("shop_name")
        _title = Details("title")
        _sale_message = Details("sale_message")
        _announcement = Details("announcement")
        _is_vacation = CBool(Details("is_vacation"))
        _vacation_message = Details("vacation_message")
        _currency_code = Details("currency_code")
        _policy_welcome = Details("policy_welcome")
        _policy_payment = Details("policy_payment")
        _policy_shipping = Details("policy_shipping")
        _policy_refunds = Details("policy_refunds")
        _policy_additional = Details("policy_additional")
        If Not Details("sections") Is Nothing Then
            _sections = New ShopSections(Of ShopSection)(CType(Details("sections"), ArrayList))
        End If
    End Sub

#End Region

End Class